package Memento;

public class EditSoftware {
    private String state;
    private UnRedoMemento unRedo;
    public EditSoftware() {
        unRedo = new UnRedoMemento();
    }
    Memento createMemento() {
        return new Memento(state);
    }
    void restoreMemento(Memento m) {
        this.state = m.getState();
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public void setAndStoreState(String state) {
        this.setState(state);
        unRedo.addMemento(this.createMemento());
    }
    public void undo() {
        Memento memento=unRedo.undo();
        if (memento!=null){
            setState(memento.getState());
        }
    }
    public void redo() {
        Memento memento=unRedo.redo();
        if (memento!=null){
            setState(memento.getState());
        }
    }
}
